﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Web.Security;

namespace ProjectEF6
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
      
        public MainWindow()
        {
            InitializeComponent();
            //Membership.CreateUser("Martinovdz2", "test123*");
            //Roles.AddUserToRole("Martinovdz2", "user");
            //Roles.AddUserToRole("Martino", "user");
            //Roles.RemoveUserFromRole("Martino", "admin");
        }

        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Password;
            DLL dllobj = new DLL();
            //Login Check
            if (dllobj.TestLogin(username, password) == "Succes")
            {
                if (dllobj.GetUserRole(username) == "admin")
                    {
                        //Admin Panel
                        PanelA Admin = new PanelA();
                        Admin.ShowDialog();
                    }
                    else
                    {
                        //User Panel
                        Panel User = new Panel();
                        User.ShowDialog();
                    }
                }
                else
                    {
                        MessageBox.Show("Incorrect login info.\nPlease try again.","Login Error");
                       
                    }
        }

        private void btnNewUser_Click(object sender, RoutedEventArgs e)
        {
            NewUser u = new NewUser();
            u.ShowDialog();
        }

        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);

            Application.Current.Shutdown();
        }
    }
}
